import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/user'
    },
    {
      path: '/user',
      component: () => import('@/views/user/UserEdit.vue'),
      meta: { title: '用户信息' }
    }, {
      path: '/address',
      component: () => import('@/views/address/AddressList.vue'),
      meta: { title: '地址列表' }
    }, {
      path: '/address/:id',
      component: () => import('@/views/address/AddressEdit.vue'),
      meta: { title: '编辑地址' }
    }
  ],
})

// 只要路由切换 就会执行 beforeEach(拦截) afterEach(可以处理一些后续事物)
router.afterEach((to, from) => {
  document.title = to.meta.title as string
})


export default router
